package br.ufpe.cin.rgms.publicacao.apresentacao;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.ufpe.cin.rgms.Facade;
import br.ufpe.cin.rgms.membro.modelo.Membro;
import br.ufpe.cin.rgms.publicacao.modelo.Publicacao;

public class RemoverPublicacaoServlet extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, IOException {
		if(((Membro) request.getSession().getAttribute("usuario")) == null){
			response.sendRedirect("index.jsp");
		}
		else{
			Publicacao publicacao = Facade.getInstance().getPublicacao((String) request.getParameter("publicacao"));
			
			Facade.getInstance().removerPublicacao(publicacao);
			
			request.setAttribute("publicacaostatus", "Publicacao removida com sucesso!");
			
			RequestDispatcher view = request.getRequestDispatcher("publicacaostatus.jsp");
			view.forward(request, response);
		}
	}

}
